package com.youcai.springboot_day03.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;


@Controller
public class loginController {

    @RequestMapping("/login")
    public String login(String name, String pass, Model model, HttpSession session) {
        if(name.equals("adim") && pass.equals("12345")){
            session.setAttribute("loginname",name);
            return "redirect:/index";
        }else {
            model.addAttribute("mes","错误");
            return "login";
        }
    }

    @RequestMapping("/user/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/index";
    }
}
